package com.murray.assignment.service.impl;

import com.murray.assignment.mapper.CartMapper;
import com.murray.assignment.mapper.UsersMapper;
import com.murray.assignment.pojo.Cart;
import com.murray.assignment.pojo.Users;
import com.murray.assignment.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.catalog.Catalog;

/**
 * @author Murray
 * @Date 2021/6/7
 * @Time 17:03
 */
@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private CartMapper cartMapper;

    @Override
    public Integer registByUsername(Users users) {
        Integer isSuccessful = usersMapper.addUserByUsername(users);
        Cart cart = new Cart();
        cart.setUserId(users.getUserId());
        cart.setTotalPrice(0);
        cart.setTotalNum(0);
        cartMapper.addCart(cart);
        System.out.println("购物车");
        return isSuccessful;
    }

    @Override
    public Integer registByMobile(Users users) {
        Integer isSuccessful = usersMapper.addUserByPhone(users);
        Cart cart = new Cart();
        cart.setUserId(users.getUserId());
        cart.setTotalNum(null);
        cart.setTotalPrice(null);
        cartMapper.addCart(cart);
        System.out.println("添加成功");
        return isSuccessful;
    }

    @Override
    public Integer isExistsUname(Users users) {
        return usersMapper.findUserByUname(users);
    }

    @Override
    public Users findUserByUnameAndUpwd(Users users) {
        return usersMapper.findUserByUnameAndUpwd(users);
    }
}
